﻿using Core.Log;
using OpenTK.Graphics.OpenGL4;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Rendering.Buffer
{
    public class IndexBufferObject : IDisposable
    {
        private readonly int _id;
        public int Length { get; }
        public IndexBufferObject(uint[] indices)
        {
            _id = GL.GenBuffer();
            Length = indices.Length;
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _id);
            GL.BufferData(BufferTarget.ElementArrayBuffer, sizeof(uint) * indices.Length, indices, BufferUsageHint.StaticDraw);
        }
        public void Bind()
        {
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _id);
        }
        public static void UnBind()
        {
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
        private void ReleaseUnmanageResources()
        {
            //GL.DeleteBuffer(_id);
        }
        public void Dispose()
        {
            ReleaseUnmanageResources();
            GC.SuppressFinalize(this);
        }
        ~IndexBufferObject()
        {
            ReleaseUnmanageResources();
        }
    }
}
